
function initLogon(){
	var em = $("logonMail");
	if (em.value === "") {
		em.focus();
	} else {
		$("password").focus();
	}
	var value = RDC.util.getCookie("cookPwrd");
	if(value !== ""){
		UtilHandler.decode(value, function(result){
			if(result !== null){
				$("password").value = result;
			}
		});
	}
}
function rememberUser(){
	var elem = $("rememberMe");
	if(elem.value != "rememberMe"){
		elem.value = "rememberMe";
	}
	else{
	    elem.value = "dontRememberMe";
	}
}
// check the Mail
function checkMail(mailId, msgId) {
	var str = "";
	var elem = $(mailId);
	var lm = elem.value;
	lm = lm.replace(/^\s+|\s+$/g, "");
	for (var i = 0, j = lm.length; i < j; i += 1) {
		var ch = lm.charCodeAt(i);
		if (ch >= 65281 && ch <= 65373) {
			str += String.fromCharCode(ch - 65248);
		} else {
			str += String.fromCharCode(ch);
		}
	}	
	str = str.replace(/·/, "@");
	elem.value = str = str.replace(/[。|,|，|、]/g, "."); 	
	var pattern = /^[A-Z_a-z0-9-\.]+@([A-Z_a-z0-9-]+\.)+[a-z0-9A-Z]{2,4}$/;
	if (pattern.test(str)) {
		RDC.gui.hideMsg(msgId);
		return true;
	} else {
		RDC.gui.showMsg(msgId, "\u90ae\u7bb1\u5730\u5740\u683c\u5f0f\u4e0d\u6b63\u786e.");
		return false;
	}
}
// check the password in a simple way
function simpleCheckPwd(pwdId, msgId) {
	var pval = $(pwdId).value;
	if (pval == "") {
		RDC.gui.showMsg(msgId, "\u5bc6\u7801\u4e0d\u80fd\u4e3a\u7a7a");
		return false;
	} else {
		if (pval.length < 6 || pval.length > 16) {
			RDC.gui.showMsg(msgId, "\u5bc6\u7801\u957f\u5ea6\u57286~16\u4e4b\u95f4");			
			return false;
		}
	}
	RDC.gui.hideMsg(msgId);
	return true;
}
// check the form before logging on
function checkLogonInputs() {
	if (!checkMail("logonMail", "logonMessage")) {
		$("logonMail").focus();
		return false;
	}
	if (!simpleCheckPwd("password", "logonMessage")) {
		$("password").focus();
		return false;
	}
	RDC.gui.disable("logonbtn");
	return true;
}
// check the random codes
function checkRandCodes(codesId, msgId) {
	var cds = $(codesId).value;
	if (cds == "") {
		RDC.gui.showMsg(msgId, "\u8bf7\u8f93\u5165\u9a8c\u8bc1\u7801.");
		return false;
	} else {
		//the validation codes consist of 4 numbders
		var chf = /\d{4}/;
		if (!chf.test(cds)) {
			RDC.gui.showMsg(msgId, "\u9a8c\u8bc1\u7801\u683c\u5f0f\u4e0d\u6b63\u786e.");
			return false;
		}
	}
	RDC.gui.hideMsg(msgId);
	return true;
}
function checkSignfInputs() {
	if (!checkMail("regMail", "regMessage")) {
		$("regMail").focus();
		return false;
	}
	if (!checkRandCodes("codes", "regMessage")) {
		$("codes").focus();
		return false;
	}
	RDC.gui.disable("signfSubmit");
	return true;
}

// check the form before getting a temp password
function checkPwdInputs() {
	if (!checkMail("pwdMail", "pwdMessage")) {
		$("pwdMail").focus();
		return false;
	}
	if (!checkRandCodes("codes", "pwdMessage")) {
		$("codes").focus();
		return false;
	}
	RDC.gui.disable("pwdSubmit");
	return true;
}
// check if the password is set simply
function isPwdTooSimple(pwd) {
	var patrn = /^(\w|\`|\~|\!|\@|\#|\$|\%|\^|\&|\*|\(|\)|\_|\+|\{|\}|\:|\"|\||\<|\>|\?|\=|\-|\]|\[|\\|\'|\;|\/|\.|\,)\1*$/;
	var num = "12345678909876543210";
	if (pwd.length < 6) {
		return true;
	} else {
		if (patrn.test(pwd) == true) {
			return true;
		} else {
			if (num.indexOf(pwd) != -1) {
				return true;
			} else {
				return false;
			}
		}
	}
}
// check the password in a complex way
function checkPassword() {
	var pwdId = "password";
	var msgId = "pwdMsg";
	var pval = $(pwdId).value;
	if (isEmpty(pval)) {
		RDC.gui.showMsg(msgId, "密码不能全为空格");
		return false;
	} else {
		if (pval.length < 6 || pval.length > 16) {
			RDC.gui.showMsg(msgId, "\u5bc6\u7801\u957f\u5ea6\u57286~16\u4e4b\u95f4");
			return false;
		} else {
			if (isPwdTooSimple(pval) == true) {
				RDC.gui.showMsg(msgId, "\u5bc6\u7801\u8fc7\u4e8e\u7b80\u5355\uff0c\u8bf7\u4fee\u6539");
				return false;
			}
		}
	}
	RDC.gui.hideMsg(msgId);
	return true;
}
function isEmpty(str) {
	var pat = /\S{1,}/;
	if(pat.test(str)) 
		return false;
	return true;
}
// check the password user enters for the second time
function checkConfirmPassword() {
	var pwdId = "password";
	var conPwdId = "confirmPassword";
	var msgId = "confPwdMsg";
	if ($(conPwdId).value == "") {
		return false;
	}
	if ($(pwdId).value != $(conPwdId).value) {
		RDC.gui.showMsg(msgId, "\u4e24\u6b21\u5bc6\u7801\u4e0d\u4e00\u81f4");
		return false;
	} else {
		RDC.gui.hideMsg(msgId);
		return true;
	}
}
// check the user's real name
function checkRealName() {
	var msgId = "nameMsg";
	var name = $("realName").value;
	if (name == "") {
		RDC.gui.showMsg(msgId, "\u771f\u5b9e\u59d3\u540d\u4e0d\u80fd\u4e3a\u7a7a");
		return false;
	}
	if (name.length > 30) {
		RDC.gui.showMsg(msgId, "\u82f1\u6587\u540d\u4e0d\u8d85\u8fc730\u4e2a\u5b57\u7b26");
		return false;
	}
	if (chinese(name) < 2) {
		RDC.gui.showMsg(msgId, "\u4e2d\u6587\u540d\u4e0d\u80fd\u5c11\u4e8e\u4e24\u4e2a\u5b57");
		//return false;
	}
	RDC.gui.hideMsg(msgId);
	return true;
}
function chinese(str) {
	var count = 0;
	for (var i = 0; i < str.length; i+=1) {
		if (str.charCodeAt(i) > 255) {
			count+=1;
		}
	}
	return count;
}
function checkRegCodes() {
	var cds = $("mailCodes").value;
	if (cds.length != 38) {
		RDC.gui.showMsg("signsMessage", "\u60a8\u8f93\u5165URL\u4e0d\u5408\u6cd5\uff0c\u8bf7\u786e\u8ba4\u53d1\u9001\u5230\u60a8\u90ae\u7bb1\u7684URL\u6216\u91cd\u65b0\u6ce8\u518c!");
		return false;
	}
	return true;
}
function checkRegInputs() {
	if (!checkRegCodes()) {
		RDC.gui.showMsg("signsMessage", "\u60a8\u8f93\u5165\u7684URL\u4e0d\u5408\u6cd5\uff01");
		return false;
	}
	if (!checkPassword()) {
		RDC.gui.showMsg("signsMessage", "\u60a8\u8f93\u5165\u7684\u5bc6\u7801\u4e0d\u5408\u6cd5\uff01");
		$("password").focus();
		return false;
	}
	if (!checkConfirmPassword()) {
		RDC.gui.showMsg("signsMessage", "\u60a8\u4e24\u6b21\u8f93\u5165\u7684\u5bc6\u7801\u4e0d\u5339\u914d\uff01");
		$("confirmPassword").focus();
		return false;
	}
	if (!checkRealName()) {
		RDC.gui.showMsg("signsMessage", "\u60a8\u8f93\u5165\u7684\u59d3\u540d\u4e0d\u5408\u6cd5\uff01");
		$("realName").focus();
		return false;
	}
	RDC.gui.disable("signsSubmit");
	return true;
}
function promptPwd() {
	// prompt for entering password
	RDC.gui.showMsg("pwdMsg", "\u5bc6\u7801\u5e94\u4e3a6-16\u4e2a\u5b57\u7b26");
}
function promptRePwd() {
	// prompt for entering password again
	RDC.gui.showMsg("confPwdMsg", "\u8bf7\u518d\u6b21\u8f93\u5165\u60a8\u7684\u5bc6\u7801");
}
function promptUserName() {
	// prompt for entering real name
	RDC.gui.showMsg("nameMsg", "\u8bf7\u8f93\u5165\u771f\u5b9e\u7684\u4e2d\u6587\u59d3\u540d");
}
// change password
function resetPwd() {
	if (!checkOldPwd()) {
		RDC.gui.showMsg("resetPwdMessage", "\u60a8\u8f93\u5165\u7684\u5bc6\u7801\u6709\u8bef");
		$("oldPassword").focus();
		return false;
	}
	if (!checkPassword()) {
		RDC.gui.showMsg("resetPwdMessage", "\u60a8\u8f93\u5165\u7684\u65b0\u5bc6\u7801\u4e0d\u7b26\u5408\u89c4\u5219");
		$("password").focus();
		return false;
	}
	if (!checkConfirmPassword()) {
		RDC.gui.showMsg("resetPwdMessage", "\u60a8\u7b2c\u4e8c\u6b21\u8f93\u5165\u7684\u5bc6\u7801\u6709\u8bef");
		$("confirmPassword").focus();
		return false;
	}
	RDC.gui.hideMsg("resetPwdMessage");
	RDC.gui.disable("resetPwdSubmit");
	return true;
}
function checkOldPwd() {
	return simpleCheckPwd("oldPassword", "oldPwdMsg");
}
function promptOldPwd() {
	// prompt for entering old password
	RDC.gui.showMsg("oldPwdMsg", "\u8bf7\u8f93\u5165\u60a8\u73b0\u5728\u7684\u5bc6\u7801");
}
function goToLogin(){
	window.location.href = "/roadmap/auth/logon.jsp";
}
function goToReg(){
	window.location.href = "/roadmap/auth/signf.jsp";
}


